package cn.t222.controller.sys;

import cn.t222.pojo.Result;
import cn.t222.pojo.SysRole;
import cn.t222.service.RoleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sys")
public class RoleController {
    @Autowired private RoleService roleService;

    @PostMapping("/role/add")
    public Result add(SysRole role) {
        roleService.add(role);
        return Result.ok("200","success", null);
    }
    @GetMapping("/role/del")
    public Result del(Integer id) {
        roleService.del(id);
        return Result.ok("200","success", null);
    }
    @PostMapping("/role/update")
    public Result update(SysRole role) {
        roleService.update(role);
        return Result.ok("200","success", null);
    }
    @GetMapping("/role/get")
    public Result get(Integer id) {
        return Result.ok("200","success", roleService.get(id));
    }
    @GetMapping("/role/list")
    public Result getAll(@RequestParam(defaultValue = "1") Integer page,
                         @RequestParam(defaultValue = "10") Integer limit) {
        PageHelper.startPage(page, limit);
        List<SysRole> list = roleService.getAll();
        PageInfo<SysRole> pageInfo = PageInfo.of(list);
        return Result.ok("200","success", pageInfo);
    }
}
